SetGfxDriver 1:Graphics 800,600,8,2:SeedRnd MilliSecs() :SetBuffer FrontBuffer() 
Include "fn1.bb"

While Not KeyHit(1) 
ClsColor 0,0,0
Cls
randnum(0)
getnums()
;	fact_faza()
;	Color 255,255,210:Text 5,5,fasecnt+":  "+ tycnt+" maxfase1: "+maxfase1+" minfase2: "+minfase2+"  middle=" + ttt0+"/"+ zzz1 + ", Null cnt=" + cnull+"%, max without Null="+wnullmax+", phase=3",False ,False
erase()	
;If yyyyy="error" Then MouseWait()
;
;
;Color 210,255,210:Text 310,2,in,False ,False
zzz1=zzz1+1:hzzz1=hzzz1+1:jzzz1=jzzz1+1
Flip
If zzz1> 64  Then 

If ((bit<>2) And (tycnt>maxfase1)) Then maxfase1=tycnt
If ((bit=2) And (tycnt<minfase2)) Then minfase2=tycnt	 
;WaitMouse()
bit=mod4(bit):randnum(1):fasecnt=fasecnt+1
EndIf

VWait 
Wend 

Function erase()
checke()
End Function

Function fact_faza()
	If bit <>2 Then		
			For i = 0 To 9 
			PokeInt in5,i*5,mod2(PeekInt (in31,i*5) ) 
			PokeInt in6,i*5,mod2(PeekInt (in1,i*5) ) 		
			PokeInt in7,i*5,mod2(PeekInt (in41,i*5))			
			Next 
	Else
			For i = 0 To 9 
			PokeInt in5,i*5,mod2(PeekInt (in31,i*5) Xor Floor(PeekInt (in31,i*5)/13107)^31.5) 
			PokeInt in6,i*5,mod2(PeekInt (in1,i*5))	
			PokeInt in7,i*5,mod2(PeekInt (in41,i*5)Xor Floor(PeekInt (in41,i*5)/13107)^31.5)
			Next 
;			For i = 0 To 9 
;			PokeInt in5,i*5,mod2(PeekInt (in5,i*5)+ 5^10) 
;			PokeInt in6,i*5,mod2(PeekInt (in6,i*5))	
;			PokeInt in7,i*5,mod2(PeekInt (in7,i*5)+ 5^10)
;			Next 			
	EndIf 	
		
	For unittest=0 To 5	
		For i = 0 To 9 
		PokeInt in3,i*5,mod2(PeekInt (in5,i*5) ) 
		PokeInt in2,i*5,mod2(PeekInt (in6,i*5) ) 		
		PokeInt in4,i*5,mod2(PeekInt (in7,i*5))			
		Next 
		eee1=fact(fact(PeekInt(in2,0),PeekInt(in2,5),PeekInt(in2,10)),fact(PeekInt(in2,0+15),PeekInt(in2,5+15),PeekInt(in2,10+15)),fact(PeekInt(in2,0+2*15),PeekInt(in2,5+2*15),PeekInt(in2,10+2*15)))
		eee2=fact(fact(PeekInt(in3,0),PeekInt(in3,5),PeekInt(in3,10)),fact(PeekInt(in3,0+15),PeekInt(in3,5+15),PeekInt(in3,10+15)),fact(PeekInt(in3,0+2*15),PeekInt(in3,5+2*15),PeekInt(in3,10+2*15)))
		eee3=fact(fact(PeekInt(in4,0),PeekInt(in4,5),PeekInt(in4,10)),fact(PeekInt(in4,0+15),PeekInt(in4,5+15),PeekInt(in4,10+15)),fact(PeekInt(in4,0+2*15),PeekInt(in4,5+2*15),PeekInt(in4,10+2*15)))
		eee=fact(eee1,eee2,eee3)
		If (eee = unittest) Then jzzz(jzzz1)=jzzz(jzzz1)+1:jzzz2(jzzz1,jzzz2(jzzz1,100))=unittest:jzzz2(jzzz1,100)=jzzz2(jzzz1,100)+1
		If jzzz2(jzzz1,100)=0 Then jzzz2(jzzz1,99)=eee
	Next
	If (jzzz(jzzz1-1)<>0) And (jzzz2(jzzz1-1,0)=1) Then tycnt=tycnt+1


End Function